package com.igelato.utils;

import com.igelato.model.AdminUser;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description: 线程共享内容
 * @Author: wht
 * @Date: 2023-12-30
 */


@Slf4j
public class ThreadLocalTool {

    // token ------------------------------
    private static final ThreadLocal<String> CONTEXT_token = new ThreadLocal<>();

    public static String getToken() {
        return CONTEXT_token.get();
    }

    public static void setToken(String token) {
        CONTEXT_token.set(token);
    }

    //     user ------------------------------
    private static final ThreadLocal<AdminUser> CONTEXT_user = new ThreadLocal<>();

    public static AdminUser getUser() {
        return CONTEXT_user.get();
    }

    public static void setUser(AdminUser user) {
        CONTEXT_user.set(user);
    }

    // 时间 ------------------------------
    private static final ThreadLocal<Long> CONTEXT_time = new ThreadLocal<>();

    public static Long getTime() {
        return CONTEXT_time.get();
    }

    public static void setCurrentTime() {
        CONTEXT_time.set(System.currentTimeMillis());
    }

    public static void remove() {
        CONTEXT_token.remove();
        CONTEXT_user.remove();
        CONTEXT_time.remove();
    }
}

